package com.example.dell.fastshopping.trolley;

import android.os.Bundle;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import com.example.dell.fastshopping.R;

import butterknife.BindView;
import butterknife.ButterKnife;

/**
 * Created by ${YSH} on 2019/5/5.
 * 描述        ${TODO}
 * <p>
 * 更新者       $author$
 * 更新时间     $Data$
 * 描述         ${TODO}
 */
public class TrolleyActivity extends AppCompatActivity {
    @BindView(R.id.back)
    ImageView back;
    @BindView(R.id.title)
    TextView title;
    @BindView(R.id.rv)
    RecyclerView rv;

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_trolley);
        ButterKnife.bind(this);
        initView();
    }

    private void initView() {
        rv.setLayoutManager(new LinearLayoutManager(this));
        rv.setAdapter(new MyAdapter());
    }

    private class MyAdapter extends RecyclerView.Adapter<MyHoler> {
        @NonNull
        @Override
        public MyHoler onCreateViewHolder(@NonNull ViewGroup viewGroup, int i) {
            int type = getItemViewType(i);
            LayoutInflater inflater = LayoutInflater.from(TrolleyActivity.this);
            View inflate;
            if (type == 0) {
                inflate = inflater.inflate(R.layout.item_trolley_seller, viewGroup, false);
            } else {
                inflate = inflater.inflate(R.layout.item_trolley_goods, viewGroup, false);
            }
            return new MyHoler(inflate);
        }

        @Override
        public int getItemViewType(int position) {

            return position%2;
        }

        @Override
        public void onBindViewHolder(@NonNull MyHoler myHoler, int i) {

        }

        @Override
        public int getItemCount() {
            return 4;
        }
    }

    private class MyHoler extends RecyclerView.ViewHolder {
        public MyHoler(@NonNull View itemView) {
            super(itemView);
        }
    }
}
